<template>
	<view>
		<view class="swiper" style="padding: 20rpx;background-color: #fff;">
			<u-swiper :list="swiperList" @click="to" height="300"></u-swiper>
		</view>
		<view class="news" style="margin-top: 20rpx;">
			<u-sticky offset-top="0">
				<u-tabs :list="tabList" :is-scroll="true" :current="tabCurrent" @change="tabChange"></u-tabs>
			</u-sticky>
			<view class="news-list" style="padding: 20rpx;background-color: #fff;">
				<view class="news-item" style="display: flex;flex-direction: row;justify-content: space-between;
				align-items: center;padding: 20rpx 0;border-top: 2rpx solid #e4e7ed;" v-for="item in newsList">
					<view class="left" style="width: 450rpx;">
						<view class="top" style="height: 168rpx;">
							<text class="line" style="font-size: 32rpx;font-weight: bold;">{{item.title}}</text>
							<rich-text :nodes="item.content" class="line" style="font-size: 26rpx;"></rich-text>
						</view>
						<view class="bottom" style="display: flex;flex-direction: row;color: #666;font-size: 22rpx;">
							<text>{{item.readNum}} 阅读</text>
							<text style="margin-left: 20rpx;">{{item.publishDate}}</text>
						</view>
					</view>
					<view class="right center">
						<navigator :url="`/pages/news-detail/news-detail?id=${item.id}`">
							<image :src="$baseUrl + item.cover" mode="" style="width: 250rpx;height: 200rpx;"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				tabList: [],
				tabCurrent: 0,
				newsList: []
			};
		},
		onLoad() {
			this.getSwiper()
			this.getTab()
		},
		methods:{
			getSwiper(){
				this.$request({
					url: '/prod-api/api/rotation/list',
					data: {
						type: '2'
					}
				}).then(res => {
					this.swiperList = res.rows.map(item => ({image: this.$baseUrl + item.advImg, id: item.targetId}))
				})
			},
			to(index){
				uni.navigateTo({
					url:'/pages/news-detail/news-detail?id=' + this.swiperList[index].id 
				})
			},
			getTab(){
				this.$request({
					url: '/prod-api/press/category/list'
				}).then(res => {
					this.tabList = res.data
					this.getNews()
				})
			},
			tabChange(index){
				this.tabCurrent = index
				this.getNews()
			},
			getNews(){
				this.$request({
					url: '/prod-api/press/press/list',
					data: {
						type: this.tabList[this.tabCurrent].id
					}
				}).then(res => {
					this.newsList = res.rows
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
